//
//  Order.m
//  car
//
//  Created by chenxu on 15/3/21.
//  Copyright (c) 2015年 chenxu. All rights reserved.
//

#import "Order.h"
#import "NetAPIManager.h"
#import "Insurance.h"
#import "JSONKit.h"
@implementation Order

- (instancetype)init
{
    self = [super init];
    if (self) {
        NSLog(@"重写构造函数");
    }
    return self;
}

- (NSDictionary* )toIdParams{
    return @{
             @"Id" :  _Id
             };
}

- (NSDictionary* )toOrderidParams{
    return @{
             @"Orderid" :  _Orderid
             };
}

- (NSDictionary* )toBaiduIdParams{
    return @{
             @"Id" :  _Id
             };
}

- (NSDictionary* )toRefreshParams{
    return @{
             @"Id" : _Id
             };
}
- (NSInteger)getDevice{
    if (!_device) {
        return 0;
    }
    else if([_device isEmpty]==false && [_device intValue]==1){
        return 1;
    }
    else if([_device isEmpty]==false && [_device intValue]==2){
        return 2;
    }
    else{
        return 0;
    }
}


- (NSArray *)getXianzhong{
    _Xianzhong = [_Xianzhong stringByReplacingOccurrencesOfString:@"[" withString:@""];
    _Xianzhong = [_Xianzhong stringByReplacingOccurrencesOfString:@"]" withString:@""];
    
    
    NSArray* array = [_Xianzhong componentsSeparatedByString:@"},"];
    //处理成字典的array
    NSMutableArray* result = [[NSMutableArray alloc]init];
    for (int i = 0; i<[array count]-1; i++) {
        NSString* temp = [[array objectAtIndex:i]stringByAppendingString:@"}"];
        Insurance* ins = [NSObject objectOfClass:@"Insurance" fromJSON: [temp objectFromJSONString]];
        [result addObject:ins];
    }
    return result;
}


/*!
 *  @brief  用户发到商家，取商家信息
 */
- (void)user_setBaiduid{
    [[NetAPIManager sharedManager]user_request_baiduid:[self toBaiduIdParams] andBlock:^(id data, NSError *error) {
        _channelid = [data valueForKeyPath:@"Bchannel_id"];
        _userid = [data valueForKeyPath:@"Buser_id"];
        _device = [data valueForKeyPath:@"device"];
    }];
}
/*!
 *  @brief  商家发到用户
 */
- (void)company_setBaiduid{
    [[NetAPIManager sharedManager]company_request_baiduid:[self toBaiduIdParams] andBlock:^(id data, NSError *error) {
        _channelid = [data valueForKeyPath:@"Channel_id"];
        _userid = [data valueForKeyPath:@"User_id"];
        _device = [data valueForKeyPath:@"device"];
    }];
}




@end
